﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectSem3.admin
{
    public partial class WebForm9 : System.Web.UI.Page
    {
        private DataClasses1DataContext dc = new DataClasses1DataContext();
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                string id = Request.QueryString["id"];
                var at = this.dc.Articals.Single(a => a.articalID.Equals(id));
                this.TextBoxTitle.Text = at.title;
                this.CKEditor1.Text = at.content;
            }
            
        }

        protected void ButtonUpdate_Click(object sender, EventArgs e)
        {
            string title = this.TextBoxTitle.Text;
            string content = this.CKEditor1.Text;
            update(title, content);
            
        }
        public void update(string title, string content)
        {
            string id = Request.QueryString["id"];
            var atc = this.dc.Articals.Single(a => a.articalID.Equals(id));
            atc.title = title;
            atc.content = content;
            this.dc.SubmitChanges();
            this.LabelKetQua.Text = "Update Successful";
            
        }

        protected void ButtonCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("NewsManager.aspx");
        }
    }
}